<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/ecside.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>${title}</title>
		<link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" ></link>
		<link rel="stylesheet" href="${ctx }/static/styles/edit/box.css" ></link>
		<!--js库-->
		<%@ include file="/static/commons/jquery-easyui.jsp" %>
		<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
		<script type="text/javascript" src="${ctx}/static/scripts/check_all.js"></script>
		<style type="text/css">
			.box table caption{color: red; font-size: 12px; font-weight: normal;}
		</style>
	</head>
	<body>
		<div class="box">
		<table id="tab2" style="white-space: nowrap;">
			<caption>操作提示：点击配件重新选择</caption>
			<tbody>
				<c:if test="${not empty list }">
					<c:forEach items="${list }" var="li">
						<tr>	
							<td class="message">
								<p>故障现象：</p>
							</td>
							<td style="width: 140px;">
								<vvise:select id="faultId" name="faultId" sqlname="getFaultInfo" ifSelect="false" defval="${li.fault_id }" className="wd170" width="100%"/>
							</td>
							<td class="message">
								<p>更换配件：</p>
							</td>
							<td>
								<input type="hidden" name="partsId" value="${li.parts_id }" ></input>
								<input type="text" name="partsName" value="${li.parts_name }" class="wd170" style="cursor: pointer; width:100%;" readonly="readonly"></input>
							</td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>
		</div>
	</body>
	<script type="text/javascript">
		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
		$(function(){
			$(document).delegate('input[name="partsName"]', 'click', function(){
        		var index_ = $(this).parents('tr').index();
        		var id_ = $(this).siblings('input[name="partsId"]').val();

        		var pp = parent;
				var custId = '';
				pp.openWindow("选择配件",pp.width2,430,"${ctx}/myInspect/chooseParts?partsIds="+id_+"&op=change",[{
					text:'保存',
					iconCls:'icon-ok',
					handler:function(){
						chooseParts(index_);
					}
				},{
					text:'取消',
					iconCls:'icon-no',
					handler:function(){
						pp.closeWindow('winDiv3');
					}
				}],'','winDiv3');
			});
        	
        	var chooseParts = function(idx){
        		var pp = parent;
    			var listFrame = pp.winFrame3;
    			var ids = "";
    			var ecForm = listFrame.document.all.ec;
    			if(!checkSelect(ecForm.id,true))
    				return;
    			ids = get_checkbox_values(ecForm.id,',');
    			var partsId = "", partsName = "";
    			var idd = ids.split(",");
    			for(var i=0; i<idd.length; i++){
    				if(partsId){
    					partsId+=',', partsName+='，';
    				}
    				partsId += idd[i].split('||')[0];
    				partsName += idd[i].split('||')[1];
    			}
    			var tr_ = $('#tab2 tbody tr:eq('+idx+')');
    			updateParts(tr_, partsId, partsName);
        	};
        	
        	var updateParts = function(tr_, partsId, partsName){
        		var pp = parent;
        		var faultId = $(tr_).find('input[name="faultId"]').val();
        		var urls = "${ctx}/myInspect/doChangeParts?logId=${logId}&faultId="+faultId+"&partsId="+partsId;
				$.ajax({
					cache: false,
					type: "POST",
					headers: headers,
					url: urls,
					async: false,
				    error: function(request) {
				    	pp.$.messager.alert('操作提示',"操作失败！","error");
				    },
				    success: function(data) {
				    	if(data && "success" == data){
				    		pp.$.messager.alert('操作提示',"保存成功！","info",function(){
				    			$(tr_).find('input[name="partsId"]').val(partsId);
				    			$(tr_).find('input[name="partsName"]').val(partsName);
				    			pp.closeWindow('winDiv3');
				         	});
			        	}else{
			        		pp.$.messager.alert('操作提示',"操作失败！","error");
			        	}
				    }
				});
        	};
			
		});
	</script>
</html>